# We set:
# - SKIA_INCLUDE_DIRS
# - SKIA_LIBRARIES
# - SKIA_DEFINITIONS
# - SKIA_FOUND
# Taking into account:
# - SKIA_PREFIX

SET(SKIA_FOUND FALSE)

FIND_PATH(SKIA_BASE_INCLUDE_DIR
    core/SkBitmap.h
  PATHS
    ${SKIA_PREFIX}/include
)

IF(SKIA_BASE_INCLUDE_DIR)
  SET(SKIA_INCLUDE_DIRS
    ${SKIA_BASE_INCLUDE_DIR}/codec
    ${SKIA_BASE_INCLUDE_DIR}/core
    ${SKIA_BASE_INCLUDE_DIR}/config
    ${SKIA_BASE_INCLUDE_DIR}/images
    ${SKIA_BASE_INCLUDE_DIR}/effects
    ${SKIA_BASE_INCLUDE_DIR}/lazy
  )
ENDIF(SKIA_BASE_INCLUDE_DIR)

SET(SKIA_DEBUG
  ${SKIA_PREFIX}/out/gyp/Debug
  ${SKIA_PREFIX}/out/gyp/Debug/lib
  ${SKIA_PREFIX}/out/Debug/obj/gyp
  ${SKIA_PREFIX}/out/Debug
)
SET(SKIA_RELEASE
  ${SKIA_PREFIX}/out/gyp/Release
  ${SKIA_PREFIX}/out/gyp/Release/lib
  ${SKIA_PREFIX}/out/Release/obj/gyp
  ${SKIA_PREFIX}/out/Release
)
FIND_LIBRARY(SKIA_CORE_LIB_D NAMES skia_core PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_PORTS_LIB_D NAMES skia_ports PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_OPTS_LIB_D NAMES skia_opts PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_IMAGES_LIB_D NAMES skia_images PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_UTILS_LIB_D NAMES skia_utils PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_OPTS_SSSE3_LIB_D NAMES skia_opts_ssse3 PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_OPTS_SSE41_LIB_D NAMES skia_opts_sse41 PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_OPTS_AVX_LIB_D NAMES skia_opts_avx PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_EFFECTS_LIB_D NAMES skia_effects PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_SFNT_LIB_D NAMES skia_sfnt PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_SKGPU_LIB_D NAMES skia_skgpu PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_ETC1_LIB_D NAMES libetc1 PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_SKKTX_LIB_D NAMES libSkKTX PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_CODEC_LIB_D NAMES skia_codec PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_RAW_CODEC_LIB_D NAMES raw_codec PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_PNG_LIB_D NAMES libpng_static PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_JPG_LIB_D NAMES libjpeg-turbo PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_GIF_LIB_D NAMES giflib PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_WEBP_DEC_LIB_D NAMES libwebp_dec PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_WEBP_UTILS_LIB_D NAMES libwebp_utils PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_WEBP_DSP_LIB_D NAMES libwebp_dsp PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_DNG_SDK_LIB_D NAMES dng_sdk PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_ZLIB_LIB_D NAMES zlib PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_PIEX_LIB_D NAMES piex PATHS ${SKIA_DEBUG} NO_DEFAULT_PATH)


FIND_LIBRARY(SKIA_CORE_LIB_R NAMES skia_core PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_PORTS_LIB_R NAMES skia_ports PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_OPTS_LIB_R NAMES skia_opts PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_IMAGES_LIB_R NAMES skia_images PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_UTILS_LIB_R NAMES skia_utils PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_OPTS_SSSE3_LIB_R NAMES skia_opts_ssse3 PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_OPTS_SSE41_LIB_R NAMES skia_opts_sse41 PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_OPTS_AVX_LIB_R NAMES skia_opts_avx PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_EFFECTS_LIB_R NAMES skia_effects PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_SFNT_LIB_R NAMES skia_sfnt PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_SKGPU_LIB_R NAMES skia_skgpu PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_ETC1_LIB_R NAMES libetc1 PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_SKKTX_LIB_R NAMES libSkKTX PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_CODEC_LIB_R NAMES skia_codec PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_RAW_CODEC_LIB_R NAMES raw_codec PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_PNG_LIB_R NAMES libpng_static PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_JPG_LIB_R NAMES libjpeg-turbo PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_GIF_LIB_R NAMES giflib PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_WEBP_DEC_LIB_R NAMES libwebp_dec PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_WEBP_UTILS_LIB_R NAMES libwebp_utils PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_WEBP_DSP_LIB_R NAMES libwebp_dsp PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_DNG_SDK_LIB_R NAMES dng_sdk PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_ZLIB_LIB_R NAMES zlib PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)
FIND_LIBRARY(SKIA_PIEX_LIB_R NAMES piex PATHS ${SKIA_RELEASE} NO_DEFAULT_PATH)

IF(WIN32)

  # Assume that if we find core, we find the rest too
  IF(SKIA_BASE_INCLUDE_DIR AND SKIA_CORE_LIB_R AND SKIA_CORE_LIB_D)
    SET(SKIA_FOUND TRUE)
    SET(SKIA_LIBRARIES
      optimized ${SKIA_CORE_LIB_R}
      debug ${SKIA_CORE_LIB_D}
      optimized ${SKIA_PORTS_LIB_R}
      debug ${SKIA_PORTS_LIB_D}
      optimized ${SKIA_OPTS_LIB_R}
      debug ${SKIA_OPTS_LIB_D}
      optimized ${SKIA_IMAGES_LIB_R}
      debug ${SKIA_IMAGES_LIB_D}
      optimized ${SKIA_UTILS_LIB_R}
      debug ${SKIA_UTILS_LIB_D}
      optimized ${SKIA_OPTS_SSSE3_LIB_R}
      debug ${SKIA_OPTS_SSSE3_LIB_D}
      optimized ${SKIA_EFFECTS_LIB_R}
      debug ${SKIA_EFFECTS_LIB_D}
      optimized ${SKIA_SFNT_LIB_R}
      debug ${SKIA_SFNT_LIB_D}
      optimized ${SKIA_SKGPU_LIB_R}
      debug ${SKIA_SKGPU_LIB_D}
      Usp10.lib
      Opengl32.lib
    )

    IF(SKIA_OPTS_SSE41_LIB_D AND SKIA_OPTS_SSE41_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_OPTS_SSE41_LIB_R}
        debug ${SKIA_OPTS_SSE41_LIB_D}
      )
    ENDIF(SKIA_OPTS_SSE41_LIB_D AND SKIA_OPTS_SSE41_LIB_R)
    IF(SKIA_OPTS_AVX_LIB_D AND SKIA_OPTS_AVX_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_OPTS_AVX_LIB_R}
        debug ${SKIA_OPTS_AVX_LIB_D}
      )
    ENDIF(SKIA_OPTS_AVX_LIB_D AND SKIA_OPTS_AVX_LIB_R)
    IF(SKIA_ETC1_LIB_D AND SKIA_ETC1_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_ETC1_LIB_R}
        debug ${SKIA_ETC1_LIB_D}
      )
    ENDIF(SKIA_ETC1_LIB_D AND SKIA_ETC1_LIB_R)
    IF(SKIA_SKKTX_LIB_D AND SKIA_SKKTX_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_SKKTX_LIB_R}
        debug ${SKIA_SKKTX_LIB_D}
      )
    ENDIF(SKIA_SKKTX_LIB_D AND SKIA_SKKTX_LIB_R)
    IF(SKIA_CODEC_LIB_D AND SKIA_CODEC_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_CODEC_LIB_R}
        debug ${SKIA_CODEC_LIB_D}
      )
    ENDIF(SKIA_CODEC_LIB_D AND SKIA_CODEC_LIB_R)
    IF(SKIA_RAW_CODEC_LIB_D AND SKIA_RAW_CODEC_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_RAW_CODEC_LIB_R}
        debug ${SKIA_RAW_CODEC_LIB_D}
      )
    ENDIF(SKIA_RAW_CODEC_LIB_D AND SKIA_RAW_CODEC_LIB_R)
    IF(SKIA_PNG_LIB_D AND SKIA_PNG_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_PNG_LIB_R}
        debug ${SKIA_PNG_LIB_D}
      )
    ENDIF(SKIA_PNG_LIB_D AND SKIA_PNG_LIB_R)
    IF(SKIA_JPG_LIB_D AND SKIA_JPG_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_JPG_LIB_R}
        debug ${SKIA_JPG_LIB_D}
      )
    ENDIF(SKIA_JPG_LIB_D AND SKIA_JPG_LIB_R)
    IF(SKIA_GIF_LIB_D AND SKIA_GIF_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_GIF_LIB_R}
        debug ${SKIA_GIF_LIB_D}
      )
    ENDIF(SKIA_GIF_LIB_D AND SKIA_GIF_LIB_R)
    IF(SKIA_WEBP_DEC_LIB_D AND SKIA_WEBP_DEC_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_WEBP_DEC_LIB_R}
        debug ${SKIA_WEBP_DEC_LIB_D}
      )
    ENDIF(SKIA_WEBP_DEC_LIB_D AND SKIA_WEBP_DEC_LIB_R)
    IF(SKIA_WEBP_UTILS_LIB_D AND SKIA_WEBP_UTILS_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_WEBP_UTILS_LIB_R}
        debug ${SKIA_WEBP_UTILS_LIB_D}
      )
    ENDIF(SKIA_WEBP_UTILS_LIB_D AND SKIA_WEBP_UTILS_LIB_R)
    IF(SKIA_WEBP_DSP_LIB_D AND SKIA_WEBP_DSP_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_WEBP_DSP_LIB_R}
        debug ${SKIA_WEBP_DSP_LIB_D}
      )
    ENDIF(SKIA_WEBP_DSP_LIB_D AND SKIA_WEBP_DSP_LIB_R)
    IF(SKIA_DNG_SDK_LIB_D AND SKIA_DNG_SDK_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_DNG_SDK_LIB_R}
        debug ${SKIA_DNG_SDK_LIB_D}
      )
    ENDIF(SKIA_DNG_SDK_LIB_D AND SKIA_DNG_SDK_LIB_R)
    IF(SKIA_ZLIB_LIB_D AND SKIA_ZLIB_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_ZLIB_LIB_R}
        debug ${SKIA_ZLIB_LIB_D}
      )
    ENDIF(SKIA_ZLIB_LIB_D AND SKIA_ZLIB_LIB_R)
    IF(SKIA_PIEX_LIB_D AND SKIA_PIEX_LIB_R)
      SET(SKIA_LIBRARIES ${SKIA_LIBRARIES}
        optimized ${SKIA_PIEX_LIB_R}
        debug ${SKIA_PIEX_LIB_D}
      )
    ENDIF(SKIA_PIEX_LIB_D AND SKIA_PIEX_LIB_R)
  ENDIF(SKIA_BASE_INCLUDE_DIR AND SKIA_CORE_LIB_R AND SKIA_CORE_LIB_D)
ELSEIF(APPLE)
  IF(SKIA_BASE_INCLUDE_DIR AND SKIA_CORE_LIB_R)
    SET(SKIA_FOUND TRUE)
    # lines below don't work
    #FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundatation)
    #FIND_LIBRARY(MOBILECORESERVICES_LIBRARY ApplicationServices)
    SET(SKIA_LIBRARIES
      ${SKIA_CORE_LIB_R}
      ${SKIA_PORTS_LIB_R}
      ${SKIA_OPTS_LIB_R}
      ${SKIA_IMAGES_LIB_R}
      ${SKIA_UTILS_LIB_R}
      ${SKIA_OPTS_SSSE3_LIB_R}
      ${SKIA_EFFECTS_LIB_R}
      ${SKIA_SFNT_LIB_R}
      ${SKIA_SKGPU_LIB_R}
      "-framework CoreFoundation"
      "-framework ApplicationServices"
    )
    # avoid undefined SkTOU8 etc (skia checks NDEBUG if SK_RELEASE and
    # SK_DEBUG are undefined)
    SET(SKIA_DEFINES "-DSK_RELEASE")
  ENDIF(SKIA_BASE_INCLUDE_DIR AND SKIA_CORE_LIB_R)
ENDIF(WIN32)

# used for binary builds against older versions of skia
SET(WT_SKIA_OLD OFF CACHE BOOL "Use older version of skia (see WRasterImage-skia.C)")
IF (SKIA_FOUND)
  IF(WT_SKIA_OLD)
    SET(SKIA_DEFINES "${SKIA_DEFINES} -DWT_SKIA_OLD")
  ENDIF(WT_SKIA_OLD)
ENDIF (SKIA_FOUND)

